2020-2021 Sunseeker Telemetry and Lighting System
pmm_Reset_LPMx_5.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // This example shows transitions between a user Reset via the reset button, a
34 // software triggered BOR, and entrance into LPM3.5.
35 // Reading the reset interrupt flag from PMMIFG register is equivalent
36 // to reading from reset vector register.
37 //*******************************************************************************
38 //
39 // 1) Power on device:
40 // LED1 and LED2 off: device is running and was not in LPM3.5 mode previously.
41 //
42 // 2) Press User Reset button:
43 //
44 // LED1 turns on, device is running and has reset due to RST pin
45 // LED2 toggles on/off: device has reset due to a software BOR
46 // LED1 and LED2 on: device is now in LPM3.5
47 //
55 //
56 //********************************************************************************
57 #include "driverlib.h"
58 #include "Board.h"
59 
60 void main(void)
61 {
62  //Stop watchdog timer
63  WDT_A_hold(WDT_A_BASE);
64 
65  /*
66  * By default, the pins are unlocked unless waking
67  * up from an LPMx.5 state in which case all GPIO
68  * are previously locked.
69  *
70  */
71  PMM_unlockLPM5();
72  //Set LED1 as output pins.
73  GPIO_setAsOutputPin(
74  GPIO_PORT_LED1,
75  GPIO_PIN_LED1
76  );
77  //Set LED2 as output pins.
78  GPIO_setAsOutputPin(
79  GPIO_PORT_LED2,
80  GPIO_PIN_LED2
81  );
82 
83  //Was this reset triggered by the Reset flag?
84  if (PMM_getInterruptStatus(PMM_RST_INTERRUPT))
85  {
86  //Clear reset flag
87  PMM_clearInterrupt(PMM_RST_INTERRUPT);
89  GPIO_PORT_LED1,
90  GPIO_PIN_LED1
91  );
92  //Create a visual delay
93  __delay_cycles(1000000);
94 
95  //Trigger a software Brown Out Reset (BOR)
96  /*
97  * Base Address of PMM,
98  * Forces the devices to perform a BOR.
99  */
100  //Software trigger a BOR.
101  PMM_trigBOR();
102  }
103 
104  //Was this reset triggered by the BOR flag?
105  if (PMM_getInterruptStatus(PMM_BOR_INTERRUPT))
106  {
107  //Clear BOR flag
108  PMM_clearInterrupt(PMM_BOR_INTERRUPT);
109  GPIO_toggleOutputOnPin(
110  GPIO_PORT_LED2,
111  GPIO_PIN_LED2
112  );
113  //Create a visual delay
114  __delay_cycles(1000000);
115  GPIO_toggleOutputOnPin(
116  GPIO_PORT_LED2,
117  GPIO_PIN_LED2
118  );
119 
120  //Disable Regulator
121  /*
122  * Base Address of PMM,
123  * Regulator is turned off when going to LPM3/4.
124  * System enters LPM3.5 or LPM4.5, respectively.
125  */
126  PMM_turnOffRegulator();
127  // Enter LPM3.5
128  __bis_SR_register(LPM3_bits);
129  }
130 
131  while (1)
132  {
133  // Don't sleep
134  __no_operation();
135  }
136 }
void main(void)
__no_operation()
GPIO_setOutputHighOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
__delay_cycles(500000)